package com.centaline.androidsalesblog.overlay.local;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.Overlay;
import com.baidu.mapapi.model.LatLng;
import com.centaline.androidsalesblog.R;
import com.centaline.androidsalesblog.iml.BaiduMarkerClick;

import java.util.ArrayList;

/**
 * 周边楼盘or小区Overlay
 * Created by guilin on 16/4/19.
 */
public class AroundEstateOverlay implements BaiduMap.OnMarkerClickListener {

    final BaiduMap baiduMap;
    final BaiduMarkerClick baiduMarkerClick;

    private ArrayList<Overlay> overlayArrayList = new ArrayList<>();

    public AroundEstateOverlay(BaiduMap baiduMap, BaiduMarkerClick baiduMarkerClick) {
        this.baiduMap = baiduMap;
        this.baiduMarkerClick = baiduMarkerClick;
    }

    /**
     * 添加到地图中
     */
    public void addToMap(LatLng latLng) {
        if (baiduMap == null)
            return;
        overlayArrayList.add(baiduMap.addOverlay(new MarkerOptions()
                .position(latLng)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_around_point_blue))));
        baiduMap.animateMapStatus(MapStatusUpdateFactory.newLatLngZoom(latLng, 16f));
    }

    @Override
    public boolean onMarkerClick(Marker marker) {
        return overlayArrayList != null &&
                overlayArrayList.contains(marker) &&
                baiduMarkerClick.onMarkerClick(marker);
    }
}
